import * as userService from '../services/system/UserService';

export default {
  namespace: 'global',

  state: {
    currentUser: {
      nickName: '登录名未获取',
    },
    collapsed: false,
    notices: [],
    fetchingNotices: false,
  },

  reducers: {
    changeLayoutCollapsed(state, { payload }) {
      return {
        ...state,
        collapsed: payload,
      };
    },

    saveCurrentUser(state, { payload }) {
      return {
        ...state,
        currentUser: payload,
      };
    },
  },

  effects: {
    *fetchCurrentUser(_, { call, put }) {
      const response = yield call(userService.queryCurrentUser);
      yield put({
        type: 'saveCurrentUser',
        payload: {
          ...response.user,
          nickName: response.result.nickname,
        },
      });
    },
  },
  subscriptions: {

  },
};
